package com.corgi.grpc.server;

import com.corgi.grpc.lib.grpc.PersonGrpc;
import com.corgi.grpc.lib.grpc.PersonOuterClass;
import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import net.devh.springboot.autoconfigure.grpc.server.GrpcService;

/**
 * @title: PersonService
 * @description:
 * @author: dengmiao
 * @create: 2019-10-08 17:39
 **/
@Slf4j
@GrpcService(PersonOuterClass.class)
public class PersonService extends PersonGrpc.PersonImplBase {

	@Override
	public void sayHello(PersonOuterClass.HelloRequest request, StreamObserver<PersonOuterClass.HelloReply> responseObserver) {
		String message = "Hello " + request.getName();
		final PersonOuterClass.HelloReply.Builder replyBuilder = PersonOuterClass.HelloReply.newBuilder().setMessage(message);
		responseObserver.onNext(replyBuilder.build());
		responseObserver.onCompleted();

		log.info("Returning " +message);
	}
}
